<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增比赛')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-match-add">
            <div class="form-group">    
                <label class="col-sm-3 control-label">名称：</label>
                <div class="col-sm-8">
                    <input name="name" class="form-control" type="text"  autocomplete="off">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">时间：</label>
                <div class="col-sm-8">
                    <input name="time" class="form-control" type="text"  autocomplete="off">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">地址：</label>
                <div class="col-sm-8">
                    <input name="address" class="form-control" type="text"  autocomplete="off">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">主办单位：</label>
                <div class="col-sm-8">
                    <input name="mainUnit" class="form-control" type="text"  autocomplete="off">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">承办单位：</label>
                <div class="col-sm-8">
                    <input name="doUnit" class="form-control" type="text"  autocomplete="off">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">协办单位：</label>
                <div class="col-sm-8">
                    <input name="helpUnit" class="form-control" type="text"  autocomplete="off">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">投屏背景图：</label>
                <div class="col-sm-8">
                    <input type="file" id="file_screen" accept="image/jpg,image/jpeg,image/png"/>
                    <p class="help-block">投屏背景图，支持jpg，jpeg，png文件，大小不超过5M</p>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">比赛打分：</label>
                <div class="col-sm-8">
                    <select name="matchScore" class="form-control m-b">
                        <option value="true">是</option>
                        <option value="false">否</option>
                    </select>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <script type="text/javascript">
        var prefix = ctx + "js/match";
        $("#form-match-add").validate({
            focusCleanup: true
        });

        function submitHandler() {

            if ($.validate.form()) {
                var formData = new FormData();

                var screenFile = $('#file_screen')[0].files[0];
                if(screenFile && screenFile.size > 5 * 1024 * 1024){
                    $.modal.alertWarning("上传文件大小限制为5M以内");
                    return;
                }
                formData.append("screenFile", screenFile);

                var data =  $.common.formToJSON("form-match-add");
                for(var key in data){
                    formData.append(key, data[key]);
                }

                var config = {
                    url: prefix + "/add",
                    type: "post",
                    cache: false,
                    contentType: false,
                    processData: false,
                    data: formData,
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍后...");
                        $.modal.disable();
                    },
                    success: function(result) {
                        $.operate.successCallback(result);
                    }
                };

                $.ajax(config);
            }
        }

    </script>
</body>
</html>